package com.qinggeng.project.tool.pay.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.tool.pay.domain.PayWxpay;
import com.qinggeng.project.tool.pay.service.IPayWxpayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 微信支付信息Controller
 *
 * @author qinggeng
 * @date 2020-02-14
 */
@RestController
@RequestMapping("/tool/wxpay")
public class PayWxpayController extends BaseController
{
    @Autowired
    private IPayWxpayService payWxpayService;

    /**
     * 查询微信支付信息列表
     */
    @PreAuthorize("@ss.hasPermi('tool:wxpay:list')")
    @GetMapping("/list")
    public TableDataInfo list(PayWxpay payWxpay)
    {
        startPage();
        List<PayWxpay> list = payWxpayService.selectPayWxpayList(payWxpay);
        return getDataTable(list);
    }

    /**
     * 导出微信支付信息列表
     */
    @PreAuthorize("@ss.hasPermi('tool:wxpay:export')")
    @Log(title = "微信支付信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PayWxpay payWxpay)
    {
        List<PayWxpay> list = payWxpayService.selectPayWxpayList(payWxpay);
        ExcelUtil<PayWxpay> util = new ExcelUtil<PayWxpay>(PayWxpay.class);
        return util.exportExcel(list, "wxpay");
    }

    /**
     * 获取微信支付信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('tool:wxpay:query')")
    @GetMapping(value = "/{payId}")
    public AjaxResult getInfo(@PathVariable("payId") Long payId)
    {
        return AjaxResult.success(payWxpayService.selectPayWxpayById(payId));
    }

    /**
     * 新增微信支付信息
     */
    @PreAuthorize("@ss.hasPermi('tool:wxpay:add')")
    @Log(title = "微信支付信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PayWxpay payWxpay)
    {
        return toAjax(payWxpayService.insertPayWxpay(payWxpay));
    }

    /**
     * 修改微信支付信息
     */
    @PreAuthorize("@ss.hasPermi('tool:wxpay:edit')")
    @Log(title = "微信支付信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PayWxpay payWxpay)
    {
        return toAjax(payWxpayService.updatePayWxpay(payWxpay));
    }

    /**
     * 删除微信支付信息
     */
    @PreAuthorize("@ss.hasPermi('tool:wxpay:remove')")
    @Log(title = "微信支付信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{payIds}")
    public AjaxResult remove(@PathVariable Long[] payIds)
    {
        return toAjax(payWxpayService.deletePayWxpayByIds(payIds));
    }
}
